newCatalogueHasBeenPublished

- ๐ฌ๐ง English
- ๐ฎ๐น Italian
Function Name: newCatalogueHasBeenPublished
Author: Domenico Cerone Creation Date: 25/09/2025
Last Reviewer: Domenico Cerone
Trigger: HTTPS (onRequest)
Purpose: Sends notification when a new catalog is added to a license. Notifies users with access to the catalog, main profiles, and administrators through ZeptoMail template with catalog and license details.
Detailed Functionalityโ
1. REQUEST VALIDATIONโ
- Validates presence of required parameters:
catalogIdandlicenseId - Returns error if either parameter is missing
2. CATALOG DATA RETRIEVALโ
- Queries 'Catalogues' collection using provided
catalogId - Retrieves catalog information including
nameCatalogandwebDomain - Validates catalog existence
3. LICENSE DATA RETRIEVALโ
- Queries 'ARShadesSubscriptions' collection using provided
licenseId - Retrieves license information including
clientRef,name,subscriptionType, andlist_catalogues - Validates license existence
4. CLIENT DATA RETRIEVALโ
- Queries 'Client' collection using
clientReffrom license - Retrieves client information including
allProfileListandmainProfileList - Validates client existence
5. NOTIFICATION PREFERENCE CHECKโ
- For each profile in
allProfileList, checks if newCatalogueHasBeenPublished notification is enabled - Verifies
notification_types.newCatalogueHasBeenPublishedfield in each profile - If notification is disabled (false): skips that profile without sending email
- If notification is enabled (true): proceeds with catalog access verification
- Provides clear logging about notification preference status for each profile
6. RECIPIENTS SELECTION - TO (PRIMARY)โ
- Iterates through all profiles in
allProfileList - For each profile, checks if
list_cataloguesincludes thecatalogId - Adds profiles with catalog access to TO recipients list
- Uses email prefix as display name
7. RECIPIENTS SELECTION - CC (MAIN PROFILES)โ
- Adds all emails from
mainProfileListto CC recipients - Uses email prefix as display name
- Ensures main profiles are always notified regardless of catalog access
8. RECIPIENTS SELECTION - BCC (ADMINS)โ
- Queries 'Profiles' collection for all users with
role= 'Admin' - Adds all admin profiles to BCC recipients
- Uses email prefix as display name
9. EMAIL DATA PREPARATIONโ
- Prepares merge data for ZeptoMail template:
name: Catalog name (catalogData.nameCatalog)number3dAsset: SKU limit (uses 5000 ifskuLimitis 0)licenseName: Combined license name and subscription typecatalogueLink: Direct link to catalog with domain and catalog IDlicenseLink: Link to license management (temporary value)
10. EMAIL SENDING WITH ZEPTOMAILโ
- Uses dedicated template key for catalog publication notifications (
MAIL_TEMPLATE_KEY:13ef.8598f19fbcc5adb.k1.b3895820-4833-11f0-900d-dad70ff08860.197687d56a2) - Sends to three recipient types: TO (catalog users), CC (main profiles), BCC (admins)
- Includes all merge data for template personalization
11. RESPONSE HANDLINGโ
- Returns success response with catalog and license details
- Includes generated links for reference
- Handles and logs any errors during processing
Input (Payload)โ
Method: POST
Headers:
Content-Type: application/json
Body:
{
"catalogId": "4RAmQ13cjXo7ns1nmOOT",
"licenseId": "pkq5xTkMAIl4KiQxsFlB"
}
Parameters:
catalogId(string, required): Unique identifier of the cataloglicenseId(string, required): Unique identifier of the license
Output (Success)โ
{
"success": true,
"message": "Notifications sent successfully",
"catalogName": "POLAROID SS25 - FW24",
"number3dAsset": 5000,
"licenseName": "ARShades Pro - Standard",
"catalogueLink": "https://www.example.com/?c=4RAmQ13cjXo7ns1nmOOT",
"licenseLink": "http://studio.arshades.it/xxx"
}
Response Properties:
success(boolean): Indicates if the operation was completed successfullymessage(string): Descriptive message about the operation resultcatalogName(string): Name of the published catalognumber3dAsset(number): Number of 3D assets allowed (SKU limit or 5000 default)licenseName(string): Full license name with subscription typecatalogueLink(string): Direct URL to access the cataloglicenseLink(string): URL to license management interface
Testingโ
URL (if HTTPS): http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished
Test with Emulator:
- Avviare l'emulatore Firebase:
firebase emulators:start --only functions - Assicurarsi di usare Node.js versione 20:
nvm use 20 - Testare con curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished" \
-H "Content-Type: application/json" \
-d '{
"catalogId": "4RAmQ13cjXo7ns1nmOOT",
"licenseId": "pkq5xTkMAIl4KiQxsFlB"
}'
Postman Testing:
- Metodo: POST
- URL:
http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished - Headers:
- Key:
Content-Type - Value:
application/json
- Key:
- Body: raw JSON (vedi esempi sopra)
Deploy Commandโ
firebase deploy --only functions:newCatalogueHasBeenPublished
URL di Produzioneโ
newCatalogueHasBeenPublished: https://europe-central2-arshades-7e18a.cloudfunctions.net/newCatalogueHasBeenPublished
Function Name: newCatalogueHasBeenPublished
Autore: Domenico Cerone Data di creazione: 25/09/2025
Last Reviewer: Domenico Cerone
Trigger: HTTPS (onRequest)
Purpose: Invia notifica quando un nuovo catalogo viene aggiunto a una licenza. Notifica gli utenti con accesso al catalogo, i profili principali e gli amministratori tramite template ZeptoMail con dettagli del catalogo e della licenza.
Funzionamento Dettagliatoโ
1. VALIDAZIONE RICHIESTAโ
- Valida la presenza dei parametri richiesti:
catalogIdelicenseId - Restituisce errore se manca uno dei parametri
2. RECUPERO DATI CATALOGOโ
- Interroga la collezione 'Catalogues' usando il
catalogIdfornito - Recupera informazioni del catalogo inclusi
nameCatalogewebDomain - Valida l'esistenza del catalogo
3. RECUPERO DATI LICENZAโ
- Interroga la collezione 'ARShadesSubscriptions' usando il
licenseIdfornito - Recupera informazioni della licenza inclusi
clientRef,name,subscriptionTypeelist_catalogues - Valida l'esistenza della licenza
4. RECUPERO DATI CLIENTEโ
- Interroga la collezione 'Client' usando
clientRefdalla licenza - Recupera informazioni del cliente inclusi
allProfileListemainProfileList - Valida l'esistenza del cliente
5. CONTROLLO PREFERENZE NOTIFICHEโ
- Per ogni profilo in
allProfileList, controlla se la notifica newCatalogueHasBeenPublished รจ abilitata - Verifica il campo
notification_types.newCatalogueHasBeenPublishedin ogni profilo - Se la notifica รจ disabilitata (false): salta quel profilo senza inviare email
- Se la notifica รจ abilitata (true): procede con la verifica dell'accesso al catalogo
- Fornisce logging chiaro sullo stato delle preferenze di notifica per ogni profilo
6. SELEZIONE DESTINATARI - TO (PRIMARI)โ
- Itera attraverso tutti i profili in
allProfileList - Per ogni profilo, controlla se
list_cataloguesinclude ilcatalogId - Aggiunge profili con accesso al catalogo alla lista destinatari TO
- Usa il prefisso dell'email come nome visualizzato
7. SELEZIONE DESTINATARI - CC (PROFILI PRINCIPALI)โ
- Aggiunge tutte le email da
mainProfileListai destinatari CC - Usa il prefisso dell'email come nome visualizzato
- Garantisce che i profili principali siano sempre notificati indipendentemente dall'accesso al catalogo
8. SELEZIONE DESTINATARI - BCC (AMMINISTRATORI)โ
- Interroga la collezione 'Profiles' per tutti gli utenti con
role= 'Admin' - Aggiunge tutti i profili admin ai destinatari BCC
- Usa il prefisso dell'email come nome visualizzato
9. PREPARAZIONE DATI EMAILโ
- Prepara i dati merge per il template ZeptoMail:
name: Nome del catalogo (catalogData.nameCatalog)number3dAsset: Limite SKU (usa 5000 seskuLimitรจ 0)licenseName: Nome licenza combinato con tipo abbonamentocatalogueLink: Link diretto al catalogo con dominio e ID catalogolicenseLink: Link alla gestione licenza (valore temporaneo)
10. INVIO EMAIL CON ZEPTOMAILโ
- Usa chiave template dedicata per notifiche pubblicazione catalogo (
MAIL_TEMPLATE_KEY:13ef.8598f19fbcc5adb.k1.b3895820-4833-11f0-900d-dad70ff08860.197687d56a2) - Invia a tre tipi di destinatari: TO (utenti catalogo), CC (profili principali), BCC (admin)
- Include tutti i dati merge per personalizzazione template
11. GESTIONE RISPOSTAโ
- Restituisce risposta di successo con dettagli catalogo e licenza
- Include link generati per riferimento
- Gestisce e registra eventuali errori durante l'elaborazione
Input (Payload)โ
Metodo: POST
Headers:
Content-Type: application/json
Body:
{
"catalogId": "4RAmQ13cjXo7ns1nmOOT",
"licenseId": "pkq5xTkMAIl4KiQxsFlB"
}
Parametri:
catalogId(string, richiesto): Identificatore unico del catalogolicenseId(string, richiesto): Identificatore unico della licenza
Output (Successo)โ
{
"success": true,
"message": "Notifications sent successfully",
"catalogName": "POLAROID SS25 - FW24",
"number3dAsset": 5000,
"licenseName": "ARShades Pro - Standard",
"catalogueLink": "https://www.example.com/?c=4RAmQ13cjXo7ns1nmOOT",
"licenseLink": "http://studio.arshades.it/xxx"
}
Proprietร Risposta:
success(boolean): Indica se l'operazione รจ stata completata con successomessage(string): Messaggio descrittivo sul risultato dell'operazionecatalogName(string): Nome del catalogo pubblicatonumber3dAsset(number): Numero di asset 3D consentiti (limite SKU o 5000 predefinito)licenseName(string): Nome completo licenza con tipo abbonamentocatalogueLink(string): URL diretto per accedere al catalogolicenseLink(string): URL all'interfaccia di gestione licenza
Testingโ
URL (if HTTPS): http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished
Test con Emulator:
- Avviare l'emulatore Firebase:
firebase emulators:start --only functions - Assicurarsi di usare Node.js versione 20:
nvm use 20 - Testare con curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished" \
-H "Content-Type: application/json" \
-d '{
"catalogId": "4RAmQ13cjXo7ns1nmOOT",
"licenseId": "pkq5xTkMAIl4KiQxsFlB"
}'
Test con Postman:
- Metodo: POST
- URL:
http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished - Headers:
- Key:
Content-Type - Value:
application/json
- Key:
- Body: raw JSON (vedi esempi sopra)
Deploy Commandโ
firebase deploy --only functions:newCatalogueHasBeenPublished
URL di Produzioneโ
newCatalogueHasBeenPublished: https://europe-central2-arshades-7e18a.cloudfunctions.net/newCatalogueHasBeenPublished